using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWBCSUM
    {
        public DataRow Convert2WBCSUM(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWBCSUM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WBCMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WBCKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WBCWERK"] = " ".PadRight(3 ); 
         dwReturn["WBCABT"] = " ".PadRight(3 ); 
         dwReturn["WBCWAKZ"] = " ".PadRight(1 ); 
         dwReturn["WBCART"] = " ".PadRight(20 ); 
         dwReturn["WBCVAR"] = " ".PadRight(2 ); 
         dwReturn["WBCJHJJ"] = " ".PadRight(4 ); 
         dwReturn["WBCMM"] = " ".PadRight(4 ); 
         dwReturn["WBCNEUB"] = " ".PadRight(8 ); 
         dwReturn["WBCNEUD"] = " ".PadRight(0 ); 
         dwReturn["WBCZMENPRF"] = " ".PadRight(0 ); 
         dwReturn["WBCZWENPRF"] = " ".PadRight(0 ); 
         dwReturn["WBCAMENPRF"] = " ".PadRight(0 ); 
         dwReturn["WBCZMEPRF"] = " ".PadRight(0 ); 
         dwReturn["WBCAMEPRF"] = " ".PadRight(0 ); 
         dwReturn["WBCDPRRW"] = " ".PadRight(0 ); 
         dwReturn["WBCDPRME"] = " ".PadRight(0 ); 
         dwReturn["WBCDPRKZ"] = " ".PadRight(1 ); 
         dwReturn["WBCVARKZ"] = " ".PadRight(1 ); 
         dwReturn["WBCMIPRKZ"] = " ".PadRight(1 ); 
         dwReturn["WBCMIVPR"] = " ".PadRight(0 ); 
         dwReturn["WBCLAEAEND"] = " ".PadRight(0 ); 
         dwReturn["WBCWAKZRW"] = " ".PadRight(1 ); 
         dwReturn["WBCARTRW"] = " ".PadRight(20 ); 
         dwReturn["WBCVARRW"] = " ".PadRight(2 ); 
         dwReturn["WBCFILLER"] = " ".PadRight(31 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWBCSUM(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWBCSUM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWBCSUM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWBCSUM(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWBCSUM(dwLocal, ITXDBVERSION);
            }
            UpdateWBCSUM(dwLocal);
        }
        public void InsertWBCSUM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WBCSUM(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWBCSUM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WBCSUM WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WBCSUM  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WBCSUM";
            Return = Result;
            return Return;
        }
        public void DeleteWBCSUM(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WBCSUM   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWBCSUM(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WBCSUM SET "
                    +"WBCMANDANT= :WBCMANDANT,"
                    +"WBCKUNDNR= :WBCKUNDNR,"
                    +"WBCWERK= :WBCWERK,"
                    +"WBCABT= :WBCABT,"
                    +"WBCWAKZ= :WBCWAKZ,"
                    +"WBCART= :WBCART,"
                    +"WBCVAR= :WBCVAR,"
                    +"WBCJHJJ= :WBCJHJJ,"
                    +"WBCMM= :WBCMM,"
                    +"WBCNEUB= :WBCNEUB,"
                    +"WBCNEUD= :WBCNEUD,"
                    +"WBCZMENPRF= :WBCZMENPRF,"
                    +"WBCZWENPRF= :WBCZWENPRF,"
                    +"WBCAMENPRF= :WBCAMENPRF,"
                    +"WBCZMEPRF= :WBCZMEPRF,"
                    +"WBCAMEPRF= :WBCAMEPRF,"
                    +"WBCDPRRW= :WBCDPRRW,"
                    +"WBCDPRME= :WBCDPRME,"
                    +"WBCDPRKZ= :WBCDPRKZ,"
                    +"WBCVARKZ= :WBCVARKZ,"
                    +"WBCMIPRKZ= :WBCMIPRKZ,"
                    +"WBCMIVPR= :WBCMIVPR,"
                    +"WBCLAEAEND= :WBCLAEAEND,"
                    +"WBCWAKZRW= :WBCWAKZRW,"
                    +"WBCARTRW= :WBCARTRW,"
                    +"WBCVARRW= :WBCVARRW,"
                    +"WBCFILLER= :WBCFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WBCMANDANT", OracleType.NVarChar).Value = dwData["WBCMANDANT"].ToString(); 
          or1.Parameters.Add("WBCKUNDNR", OracleType.NVarChar).Value = dwData["WBCKUNDNR"].ToString(); 
          or1.Parameters.Add("WBCWERK", OracleType.NVarChar).Value = dwData["WBCWERK"].ToString(); 
          or1.Parameters.Add("WBCABT", OracleType.NVarChar).Value = dwData["WBCABT"].ToString(); 
          or1.Parameters.Add("WBCWAKZ", OracleType.NVarChar).Value = dwData["WBCWAKZ"].ToString(); 
          or1.Parameters.Add("WBCART", OracleType.NVarChar).Value = dwData["WBCART"].ToString(); 
          or1.Parameters.Add("WBCVAR", OracleType.NVarChar).Value = dwData["WBCVAR"].ToString(); 
          or1.Parameters.Add("WBCJHJJ", OracleType.NVarChar).Value = dwData["WBCJHJJ"].ToString(); 
          or1.Parameters.Add("WBCMM", OracleType.NVarChar).Value = dwData["WBCMM"].ToString(); 
          or1.Parameters.Add("WBCNEUB", OracleType.NVarChar).Value = dwData["WBCNEUB"].ToString(); 
          or1.Parameters.Add("WBCNEUD", OracleType.NVarChar).Value = dwData["WBCNEUD"].ToString(); 
          or1.Parameters.Add("WBCZMENPRF", OracleType.NVarChar).Value = dwData["WBCZMENPRF"].ToString(); 
          or1.Parameters.Add("WBCZWENPRF", OracleType.NVarChar).Value = dwData["WBCZWENPRF"].ToString(); 
          or1.Parameters.Add("WBCAMENPRF", OracleType.NVarChar).Value = dwData["WBCAMENPRF"].ToString(); 
          or1.Parameters.Add("WBCZMEPRF", OracleType.NVarChar).Value = dwData["WBCZMEPRF"].ToString(); 
          or1.Parameters.Add("WBCAMEPRF", OracleType.NVarChar).Value = dwData["WBCAMEPRF"].ToString(); 
          or1.Parameters.Add("WBCDPRRW", OracleType.NVarChar).Value = dwData["WBCDPRRW"].ToString(); 
          or1.Parameters.Add("WBCDPRME", OracleType.NVarChar).Value = dwData["WBCDPRME"].ToString(); 
          or1.Parameters.Add("WBCDPRKZ", OracleType.NVarChar).Value = dwData["WBCDPRKZ"].ToString(); 
          or1.Parameters.Add("WBCVARKZ", OracleType.NVarChar).Value = dwData["WBCVARKZ"].ToString(); 
          or1.Parameters.Add("WBCMIPRKZ", OracleType.NVarChar).Value = dwData["WBCMIPRKZ"].ToString(); 
          or1.Parameters.Add("WBCMIVPR", OracleType.NVarChar).Value = dwData["WBCMIVPR"].ToString(); 
          or1.Parameters.Add("WBCLAEAEND", OracleType.NVarChar).Value = dwData["WBCLAEAEND"].ToString(); 
          or1.Parameters.Add("WBCWAKZRW", OracleType.NVarChar).Value = dwData["WBCWAKZRW"].ToString(); 
          or1.Parameters.Add("WBCARTRW", OracleType.NVarChar).Value = dwData["WBCARTRW"].ToString(); 
          or1.Parameters.Add("WBCVARRW", OracleType.NVarChar).Value = dwData["WBCVARRW"].ToString(); 
          or1.Parameters.Add("WBCFILLER", OracleType.NVarChar).Value = dwData["WBCFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
